package com.youlu.campus.service.platform.impl;

import com.youlu.campus.entity.PlatformVisitorRecord;
import com.youlu.campus.service.platform.PlatformVisitorRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

@Service
@Slf4j
public class PlatformVisitorRecordServiceImpl implements PlatformVisitorRecordService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Async
    @Override
    public void create(PlatformVisitorRecord req) {
        if (Objects.isNull(req)) {
            return;
        }
        if (Objects.isNull(req.getCreatedTime())) {
            req.setCreatedTime(new Date());
        }
        mongoTemplate.insert(req);
    }
}
